using System;
using System.Runtime.InteropServices;

namespace UtilityToolsCollect.WinSystemUtilityTools
{
    [Flags]
    public enum EXECUTION_STATE:uint
    {
        ES_NULL = 0x0,
        ES_AWAYMODE_REQUIRED = 0x00000040,
        ES_CONTINUOUS = 0x80000000,
        ES_DISPLAY_REQUIRED = 0x00000002,
        ES_SYSTEM_REQUIRED = 0x00000001,
        ES_USER_PRESENT = 0x00000004
    }
    public class SetThreadExecutionStateTools
    {
        [DllImport("kernel32.dll", EntryPoint = "SetThreadExecutionState")]
        public static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
        public static void Restore() => SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
        public static void PreventSleep() => SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS);
        public static void PreventOffScreen() => SetThreadExecutionState(EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS);
        public static void PreventOffScreenAndSleep() => SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS);
        public static void ResetSleepTimer() => SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED);
        public static void ResetOffScreenTimer() => SetThreadExecutionState(EXECUTION_STATE.ES_DISPLAY_REQUIRED);
        public static void ResetOffScreenAndSleep() => SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_DISPLAY_REQUIRED);
    }
}
